package com.pd.backend.service.impl;

import com.pd.backend.entity.PdAreaBoundaries;
import com.pd.backend.dao.PdAreaBoundariesDao;
import com.pd.backend.service.PdAreaBoundariesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 行政区域临时表(PdAreaBoundaries)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:32
 */
@Service("pdAreaBoundariesService")
public class PdAreaBoundariesServiceImpl implements PdAreaBoundariesService {
    @Resource
    private PdAreaBoundariesDao pdAreaBoundariesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdAreaBoundaries queryById(String id) {
        return this.pdAreaBoundariesDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdAreaBoundaries 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdAreaBoundaries> queryByPage(PdAreaBoundaries pdAreaBoundaries, PageRequest pageRequest) {
        long total = this.pdAreaBoundariesDao.count(pdAreaBoundaries);
        return new PageImpl<>(this.pdAreaBoundariesDao.queryAllByLimit(pdAreaBoundaries, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdAreaBoundaries 实例对象
     * @return 实例对象
     */
    @Override
    public PdAreaBoundaries insert(PdAreaBoundaries pdAreaBoundaries) {
        this.pdAreaBoundariesDao.insert(pdAreaBoundaries);
        return pdAreaBoundaries;
    }

    /**
     * 修改数据
     *
     * @param pdAreaBoundaries 实例对象
     * @return 实例对象
     */
    @Override
    public PdAreaBoundaries update(PdAreaBoundaries pdAreaBoundaries) {
        this.pdAreaBoundariesDao.update(pdAreaBoundaries);
        return this.queryById(pdAreaBoundaries.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdAreaBoundariesDao.deleteById(id) > 0;
    }
}
